 //
//  InventoryDetailsViewController.m
//  DA_V
//
//  Created by 周季阳 on 15/5/7.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//

#import "InventoryDetailsViewController.h"
#import "InterFace.h"
#import "UIViewAdditions.h"
#import "InDetailsTableViewCell.h"
#import "YoungAllData.h"
@interface InventoryDetailsViewController ()<UITableViewDataSource,UITableViewDelegate,YoungDelegate>
{
    UITableView *zTableView;
    UIView *belowView ;
}
@property(nonatomic,retain)NSMutableArray *zArrayData;
@end

@implementation InventoryDetailsViewController
@synthesize categoryIDStr,titleStr,zArrayData;
#pragma mark - viewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBarHidden=YES;
    
    self.view.backgroundColor = [self colorWithHexString:@"#F5F5F5"];
    [self initNav];
    navTitle.text = titleStr;
    
    YoungAllData *data = [[YoungAllData alloc]init];
    data.delegate = self;
    [data productStock:[[NSUserDefaults standardUserDefaults]objectForKey:@"userID"] andCategoryID:categoryIDStr];
    
}
#pragma mark - 商品库存回调
-(void)productStock:(NSDictionary *)sign{
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
    zArrayData = [[NSMutableArray alloc]initWithArray:[sign objectForKey:@"data"]];
    [self initUI];
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];

    }
}
#pragma mark - 商品库存回调失败
-(void)requistFail{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"网络异常,无法加载数据" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}
#pragma mark - initUI
-(void)initUI{
    belowView = [[UIView alloc]initWithFrame:CGRectMake(0, navView.bottom, SCREEN_WIDTH, SCREEN_HEIGHT-140-64-50)];
    belowView.backgroundColor = [UIColor whiteColor];
    belowView.userInteractionEnabled = YES;
    [self.view addSubview:belowView];
    
    
    UILabel *zNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, SCREEN_WIDTH/2, 30)];
    zNameLabel.textColor = [UIColor grayColor];
    zNameLabel.text = @"商品";
    zNameLabel.textAlignment = NSTextAlignmentCenter;
    zNameLabel.font = [UIFont systemFontOfSize:14];
    [belowView addSubview:zNameLabel];
    
    
    UILabel *zNumberLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2,20, SCREEN_WIDTH/2-10, 30)];
    zNumberLabel.textColor = [UIColor grayColor];
    zNumberLabel.text = @"数量";
    zNumberLabel.textAlignment = NSTextAlignmentCenter;
    zNumberLabel.font = [UIFont systemFontOfSize:14];
    [belowView addSubview:zNumberLabel];
    
    [self createrOffLineUI:CGRectMake(10, 20, SCREEN_WIDTH-20, 0.5)];
    [self createrOffLineUI:CGRectMake(10, 50, SCREEN_WIDTH-20, 0.5)];
    [self createrOffLineUI:CGRectMake(10, 20, 0.5, 30)];
    [self createrOffLineUI:CGRectMake(SCREEN_WIDTH-10, 20, 0.5, 30)];
    [self createrOffLineUI:CGRectMake(SCREEN_WIDTH/2, 20, 0.5, 30)];
    
    
    zTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,51, SCREEN_WIDTH, belowView.frame.size.height-60+10)];
    //zTableView.backgroundColor = [UIColor redColor];
    zTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    zTableView.delegate = self;
    zTableView.dataSource = self;
    zTableView.bounces = NO;
    [belowView addSubview:zTableView];
    
}
#pragma mark - UitableView delegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [zArrayData count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 30;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    InDetailsTableViewCell *cell = [[InDetailsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    
    cell.zName.text = [NSString stringWithFormat:@"%@",[[zArrayData objectAtIndex:indexPath.row] objectForKey:@"ProductName"]];
    cell.zNumber.text = [NSString stringWithFormat:@"%@",[[zArrayData objectAtIndex:indexPath.row] objectForKey:@"Stock"]];
    
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
#pragma mark - 返回
-(void)clickBackBtn{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)createrOffLineUI:(CGRect)rect{
    UIView *lines = [[UIView alloc] initWithFrame:rect];
    lines.backgroundColor = [UIColor colorWithRed:179/255.0 green:179/255.0 blue:179/255.0 alpha:1];
    [belowView addSubview:lines];
}

@end
